
import java.io.*;
import java.util.Hashtable;
import java.util.Scanner;
import java.util.StringTokenizer;
//import java.util.Enumeration;

 
// Rtype Instructions include :
   // add,sub
// Itype Instructions include :
  // load,store,bez,addi
// add 	 rd, rs, rt 	 100000 
// sub 	 rd, rs, rt 	 100010 
// load r1, 0(r2)        100011
// store r1, 0(r2)       100100
// bez r1, done          100110 branch if register is equal to zero       
// addi r1, r0, imm      100111  


public class test1 {

	//static String[] rtype ={"add","sub"};
	//static String[] itype ={"load","store","bez","addi"};
    @SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
        Scanner s = null;
        
     // Forming the Key Value pairs by using a Hasp-map, we can also use a Hash-table here!!	  
  	  Hashtable<String, String> ht = new Hashtable<String,String>();
      // forming the Key value pairs for the Instructions both R-type and I-type
      
      ht.put("add","100000");
      ht.put("sub","100010");
      ht.put("load","100011");
      ht.put("Store","100100");
      ht.put("bez","100110");
      ht.put("addi","100111");
      // forming the key value pairs for the registers 
      
      ht.put("r0", "00000");
      ht.put("r1", "00001");
      ht.put("r2", "00010");
      ht.put("r3", "00011");
      ht.put("r4", "00100");
      ht.put("r5", "00101");
      ht.put("r6", "00110");
      ht.put("r7", "00111");
      ht.put("r8", "01000");
      ht.put("r9", "01001");
      ht.put("r10", "01010");
      ht.put("r11", "01011");
      ht.put("r12", "01100");
      ht.put("r13", "01101");
      ht.put("r14", "01110");
      ht.put("r15", "01111");
      ht.put("r16", "10000");
      ht.put("r17", "10001");
      ht.put("r18", "10010");
      ht.put("r19", "10011");
      ht.put("r20", "10100");
      ht.put("r21", "10101");
      ht.put("r22", "10110");
      ht.put("r23", "10111");
      ht.put("r24", "11000");
      ht.put("r25", "11001");
      ht.put("r26", "11010");
      ht.put("r27", "11011");
      ht.put("r28", "11100");
      ht.put("r29", "11101");
      ht.put("r30", "11110");
      ht.put("r31", "11111");
        //Scanner s1 = null;
        try {
        	//int i = 0;
            s = new Scanner(new BufferedReader(new FileReader("C:\\Users\\User\\Desktop\\CA\\example.txt")));
            //s.useDelimiter(", *");
            s.useDelimiter(", *");
            
            while (s.hasNext()) {
                //System.out.println(s.next());
            	 //i++;
            	 String str1 ;
            	 str1 = s.next();
            	 //s1 = new Scanner(new BufferedReader(new FileReader("str1")));
            	 StringTokenizer st = new StringTokenizer(str1);
                 while (st.hasMoreTokens()) {
                     System.out.println(st.nextToken());
                     //String str2 ;
                     /*str2 = st.nextToken();
                     
                     // This str2 is the value of token that is present in the hashtable and we have to 
                     // check if this is there in the hash table and return its value if the key matches
                     // The key is the str2 itself and the value is the binary value .
                     Enumeration keys = ht.keys();
                    while (keys.hasMoreElements()) {
                       Object key = keys.equals(str2);
                       
                       key = str2;
                       Object value = ht.get(key);
                       
                      System.out.println(key+" : "+value);
                     } */
                    
                 }

            	}
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
}



